#! /usr/bin/env python
# -*- coding: utf-8 -*-

import os

split_count = 2
base_path = r'/rootfs/media/kasim/Data1/data/FaceBaidu'
list_file_path = r'/rootfs/media/kasim/Data1/data/FaceBaidu/file_list.txt'


def main():
    file_info_list = []
    with open(list_file_path, 'r') as file:
        for file_name in file.readlines():
            file_info_list.append(file_name)

    total_file_count = len(file_info_list)
    inter_count = total_file_count / split_count
    split_counts = []
    for i in range(1, split_count):
        split_counts.append(int(inter_count*i))
    idx = 0
    split_idx = []
    for i in range(total_file_count):
        if i >= split_counts[idx]:
            split_idx.append(i)
            idx += 1
            if idx >= (split_count-1):
                break

    i = 0
    idx = 0
    file_name = os.path.splitext(list_file_path)[0]+str(idx)+'.txt'
    file = open(file_name, 'w')
    print(file_name)
    for file_info in file_info_list:
        file.write(file_info)
        i += 1
        if (idx < (split_count-1)) and (i >= split_idx[idx]):
            file.close()
            idx += 1
            file_name = os.path.splitext(list_file_path)[0] + str(idx) + '.txt'
            file = open(file_name, 'w')
            print(file_name, i, split_idx[idx-1])
    file.close()


if __name__ == '__main__':
    main()
    print('Finish!')
